package com.example.LibrarySystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.LibrarySystem.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 根据账号密码获取User对象
     * @param account
     * @param password
     * @return
     */
    @Select("select * from users where account = #{account} and password = #{password}")
    public User getUserByUsernameAndPassword(String account,String password);

    /**
     * 根据id 获取user
     */
    @Select("select * from users where id = #{id}")
    public User getUserById(int id);

    /**
     * 根据id 获取role
     */
    @Select("select role_name from users where id = #{id}")
    public String getRoleById(int id);

    @Update("update users set password = #{password} where id = #{id}")
    public int updatePassword(int id,String password);
}
